package com.ty.springbootweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ty.springbootweb.entity.User;
import com.ty.springbootweb.mapper.UserMapper;
import com.ty.springbootweb.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * UserServiceImpl
 *
 * @aurhor Administrator  whs
 * @since 2024/9/4
 */
@Service()
public class UserServiceImpl implements UserService {
    @Resource
    public UserMapper userMapper;

    /**
     * 登录功能
     *
     * @param usrName
     * @param usrPassword
     */
    @Override
    public User login(String usrName, String usrPassword) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("usr_name", usrName);
        qw.eq("usr_password", usrPassword);
        User user = userMapper.selectOne(qw);
        return user;
    }

    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @Override
    public int addUser(User user) {
        return userMapper.insert(user);
    }

    /**
     * 删除用户
     *
     * @param
     * @return
     */
    @Override
    public int deleteUser(Long usrId) {
        return userMapper.deleteById(usrId);
    }

    /**
     * 修改用户
     *
     * @param user
     * @return
     */
    @Override
    public int updateUser(User user) {
        return userMapper.updateById(user);
    }

    /**
     * 根据id查询用户
     *
     * @param usrId
     * @return
     */
    @Override
    public User getUser(Long usrId) {
        return userMapper.selectOne(new QueryWrapper<User>().eq("usr_id", usrId));
    }

    /**
     * 查询所有用户
     *
     * @return
     */
    @Override
    public List<User> findAllUsers() {
        return userMapper.selectList(null);
    }
}